﻿Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports Oracle.DataAccess.Client

Class MainWindow
    Dim myImage As Image
    Dim myConn As SqlConnection
    Public Function ExtractImage()
        Try
            Dim cmdSelect As New SqlCommand("select PhotoBlob from Photos where PhotoID=4", myConn)
            Dim barrImg As Byte() = DirectCast(cmdSelect.ExecuteScalar(), Byte())
            Dim strfn As String = Convert.ToString(DateTime.Now.ToFileTime())
            Dim fs As New FileStream(strfn, FileMode.CreateNew, FileAccess.Write)
            fs.Write(barrImg, 0, barrImg.Length)
            fs.Flush()
            fs.Close()
            Dim myImg As New BitmapImage
            myImg.BeginInit()
            myImg.UriSource = New Uri(System.Environment.CurrentDirectory & "\" & strfn)
            myImg.EndInit()
            imgDBExtract.Source = myImg
        Catch ex As Exception
            MsgBox(ex.ToString, MsgBoxStyle.Critical, "eXTRACT IMAGE")
        End Try
    End Function

    Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnShow.Click
        Try
            myConn = New SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=TestIdentity;Integrated Security=True;User Id=501162905")
            myConn.Open()
            If myConn.State = 1 Then
                ExtractImage()
            End If
        Catch ex As Exception
            MsgBox(ex.ToString, MsgBoxStyle.Critical, "cONNECT CLICK")
        End Try
    End Sub


    Private Sub btnOracle_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnOracle.Click
        Try

            Dim strConn As String = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=pion.modspace.com)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=prod8)));User Id=space;Password=space_dev991;"
            Dim myOConn As OracleConnection
            myOConn = New OracleConnection(strConn)
            myOConn.Open()
            MsgBox(myOConn.State)
        Catch ex As Exception
            MsgBox(ex.ToString, MsgBoxStyle.Critical, "Oracle Click")
        End Try

    End Sub
End Class
